/*
 * Copyright (c) 2024 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// Autogenerated file -- DO NOT EDIT!

#include "src/adapter_dynamic/runtime_adapter_dynamic.h"
#include "dyn_intrinsics_opcodes.inc"

namespace libabckit {

// NOLINTNEXTLINE(readability-function-size)
static inline AbckitIsaApiStaticOpcode GetStaticIntrinsicOpcode(ark::compiler::IntrinsicInst *inst) {
    switch(inst->GetIntrinsicId()) {
% Compiler::intrinsics.select {|intrinsic| intrinsic.space == "abckit" }.each do |intrinsic|
        case ark::compiler::RuntimeInterface::IntrinsicId::<%= intrinsic.entrypoint_name %>:
            return ABCKIT_ISA_API_STATIC_OPCODE_<%= intrinsic.class_name.upcase %>;
% end
        default: {
            LIBABCKIT_UNREACHABLE;
            //return GetDYNIntrinsicOpcode(inst);
        }
    }
}

static inline AbckitIsaApiDynamicOpcode GetDynamicIntrinsicOpcode(ark::compiler::IntrinsicInst *inst) {
    return GetDYNIntrinsicOpcode(inst);
}

// NOLINTNEXTLINE(readability-function-size)
static inline size_t GetIntrinicMaxInputsCountStatic(ark::compiler::IntrinsicInst *inst) {
    switch(inst->GetIntrinsicId()) {
% Compiler::intrinsics.select {|intrinsic| intrinsic.space == "abckit" }.each do |intrinsic|
        case ark::compiler::RuntimeInterface::IntrinsicId::<%= intrinsic.entrypoint_name %>: {
%   inst = nil
%   Panda::instructions.each do |asm_ins|
%     if (asm_ins.mnemonic == intrinsic.method_name)
%       inst = asm_ins
%     end
%   end
%   if inst.mnemonic.include? "range"
            return -1;
%   else
%     num_vregs = inst.operands.select{|b| b.reg? && b.src?}.length
%     num_inputs = inst.acc.include?("in") ? num_vregs + 1 : num_vregs
            return <%= num_inputs %>;
%   end
        }
% end
        default: {
            LIBABCKIT_UNREACHABLE;
        }
    }
}

static inline size_t GetIntrinicMaxInputsCountDyn(ark::compiler::IntrinsicInst *inst) {
    return GetIntrinicDYNMaxInputsCount(inst);
}

// NOLINTNEXTLINE(readability-function-size)
static inline bool IsCallInstStatic(ark::compiler::Inst *inst) {
    if (!inst->IsIntrinsic()) {
        return inst->IsCall();
    }
    switch(inst->CastToIntrinsic()->GetIntrinsicId()) {
% Compiler::intrinsics.select {|intrinsic| intrinsic.space == "abckit" }.each do |intrinsic|
        case ark::compiler::RuntimeInterface::IntrinsicId::<%= intrinsic.entrypoint_name %>: {
%   inst = nil
%   Panda::instructions.each do |asm_ins|
%     if (asm_ins.mnemonic == intrinsic.method_name)
%       inst = asm_ins
%     end
%   end
%   is_call = inst.properties.include? 'call'
%   if is_call
            return true;
%   else
            return false;
%   end
        }
% end
        default: {
            LIBABCKIT_UNREACHABLE;
        }
    }
}

static inline bool IsCallInstDyn(ark::compiler::Inst *inst) {
    return IsCallDYNInst(inst);
}

}   // libabckit
